package com.demo.cotroller;

import com.demo.bean.Girls;
import com.demo.bean.Name;
import com.demo.bean.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangzhanjin on 2018/6/8.
 */
@Controller
public class HomeController {

    /**
     * ！！！！！！！！！！！！！！！！！
     * 1.严禁定义这种类的成员变量，
     * 这种全局变量有可能，会忘记清除！出现堆内存空间溢出
     * 这个list只会越来越大
     */
    private List<Name> listNeverClose = new ArrayList<>();

    @RequestMapping("/test")
    @ResponseBody
    public String test() {
        //每次进入该方法都是new的，所以相当于会被回收的
        List<Girls> listColse = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            //2.多次new
            Student student = new Student();
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //存在内存泄漏点
            listNeverClose.add(new Name());
            listColse.add(new Girls());
        }
        return "黄河之水天上来";
    }
}
